package com.yitong.equipment.ui.viewmodel

import android.app.Application
import androidx.annotation.NonNull
import androidx.lifecycle.MutableLiveData
import com.yitong.equipment.base.BaseViewModel
import com.yitong.equipment.database.entity.User
import com.yitong.equipment.entity.base.BaseReq
import com.yitong.equipment.entity.base.BaseRes
import com.yitong.equipment.entity.res.HomeDataRes
import com.yitong.equipment.network.ApiCallback
import com.yitong.equipment.network.SubscriberCallBack
import io.reactivex.disposables.Disposable

class MallViewModel(@NonNull application: Application) : BaseViewModel(application)  {

    val homeData by lazy { MutableLiveData<BaseRes<HomeDataRes>>() }
    val listUsers by lazy { MutableLiveData<List<User>>() }

    /**
     * 首页数据接口
     */
    fun getData() {
        var req = BaseReq()
        apiService.getHomeData(req).execute(SubscriberCallBack(object : ApiCallback<BaseRes<HomeDataRes>> {

            override fun onSuccess(model: BaseRes<HomeDataRes>) {
                homeData.value = model
            }

            override fun onFailure(code: Int, msg: String?) {
            }

            override fun onSubscribe(d: Disposable?) {
                addDisposable(d)
            }

            override fun onCompleted() {

            }

        }))

    }
}